﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace jinquantesthuiyuan_system
{
    public partial class Form1 : Form
    {
        static public string username;
        static public string password;
        public Form1()
        {
            InitializeComponent();
            StartPosition = FormStartPosition.CenterScreen;
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(textBox1.Text == string.Empty)
            {
                MessageBox.Show("用户名不能为空！");
                return;
            }
            if (textBox2.Text == string.Empty)
            {
                MessageBox.Show("密码不能为空！");
                return;
            }
            //连接数据库
            try
            {
                string Con = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=huiyuan.accdb";
                OleDbConnection dbconn = new OleDbConnection(Con);
                dbconn.Open();//建立连接
                string sql = string.Format("SELECT ID, `username`, `password` FROM `jq_admin` where username = '" + textBox1.Text + "' and password = '" + textBox2.Text + "'");
                OleDbCommand os1 = new OleDbCommand(sql, dbconn);
                OleDbDataReader s1 = os1.ExecuteReader();
                if (s1.Read())
                {
                    username = textBox1.Text;
                    password = textBox2.Text;
                    MessageBox.Show("登录成功！");
                    Hide();
                    HY os = new HY();//打开HY页面
                    os.StartPosition = FormStartPosition.CenterScreen;
                    os.ShowDialog();
                    Close();
                }
                else
                {
                    MessageBox.Show("账号密码错误！");
                    return;
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show("登录失败提示：" + "\r\n" + ex);
            }
            //if(textBox1.Text == "admin" && textBox2.Text == "123456")
            //{
            //    Hide();
            //    HY os = new HY();//打开HY页面
            //    os.StartPosition = FormStartPosition.CenterScreen;
            //    os.ShowDialog();
            //    Close();
            //}
            //else
            //{
            //    MessageBox.Show("账号密码错误！");
            //    return;
            //}
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //取消登录
            Close();
        }
    }
}
